package com.zxjbyte.yiyi.framework.mybatis.injector;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
import com.zxjbyte.yiyi.framework.mybatis.injector.method.InsertIgnore;
import com.zxjbyte.yiyi.framework.mybatis.injector.method.Replace;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 创建自定义sql注入器
 * @Author zhangxingjia
 * @Date 2023/3/14 9:48
 * @Version: 1.0
 */
public class YiyiSqlInjector extends DefaultSqlInjector {

    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        List<AbstractMethod> methodList = new ArrayList<>();
        methodList.add(new InsertIgnore());
        methodList.add(new Replace());
        methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));
        methodList.addAll(super.getMethodList(mapperClass, tableInfo));
        return Collections.unmodifiableList(methodList);
    }
}
